home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_exmh.idb / usr / freeware / lib / exmh-2.5 / html_maps.tcl.z / html_maps.tcl
Text File  |  2002-07-08  |  7KB  |  289 lines

  1. # maps.tcl --
  2. #    This file defines tables (i.e., maps) that drive the
  3. #    user interface and editting engine.
  4. #
  5. #    Note: the term "HTML tag" refers to an element of HTML markup
  6. #    such as <p> or <strong>.  An unqualified "tag" usually refers
  7. #    to a tag in the Tk text widget, which applies to a range of text.
  8. #
  9.  
  10. proc Map_Init {} {
  11.  
  12.     # The Node map identifies HTML-tags that define nodes (i.e. paragraphs) in
  13.     # the document.  Each node is labeled with a Tk text tag that identifies
  14.     # the type and extent of the node.  The value of the map really isn't used,
  15.     # instead just the existence of map elements is tested.
  16.     global NodeMap
  17.     array set NodeMap {
  18.     div        /div
  19.     p        /p
  20.     h1        /h1
  21.     h2        /h2
  22.     h3        /h3
  23.     h4        /h4
  24.     h5        /h5
  25.     h6        /h6
  26.     blockquote /blockquote
  27.     } 
  28.  
  29.     global StructureMap
  30.     array set StructureMap {
  31.     pre        /pre
  32.     applet    {helps for output sorting}
  33.     form    ditto
  34.     frame    -
  35.     }
  36.  
  37.     # The SingletonMap defines HTML-tags that usually occur in isolation.
  38.     # They result in a text mark at their location.
  39.     global SingletonMap
  40.     array set SingletonMap {
  41.         br        -
  42.         hr        -
  43.         input    -
  44.         img        -
  45.         li        -
  46.         dd        -
  47.         dt        -
  48.         base    -
  49.         x-insert    -
  50.         param    -
  51.         embed    -
  52.         webtk    -
  53.     }
  54.     # This is used to tweak sorting for list item tags
  55.     # They sort after open list tags
  56.     global ListSingletonMap
  57.     array set ListSingletonMap {
  58.     li    -
  59.     dd    -
  60.     dt    -
  61.     }
  62.     # These singletons sort before anything
  63.     global HighSingletonMap
  64.     array set HighSingletonMap {
  65.     param -
  66.     x-insert -
  67.     }
  68.     # The rest of the singletons sort after all other tags
  69.     
  70.     # The Break map identifies HTML-tags that require newlines.
  71.     # br is special because it can cause multiple newlines.
  72.     global BreakMap
  73.     array set BreakMap {
  74.     hr        -
  75.     li        -
  76.     dt        -
  77.     dd        -
  78.     pre        /pre
  79.     p        /p
  80.     div        /div
  81.     h1        /h1
  82.     h2        /h2
  83.     h3        /h3
  84.     h4        /h4
  85.     h5        /h5
  86.     h6        /h6
  87.     blockquote /blockquote
  88.     ol        -
  89.     ul        -
  90.     dl        -
  91.     menu    -
  92.     dir        -
  93.     form    -
  94.     }
  95.  
  96.     # The IgnoreMap defines HTML-tags that need neither a mark or a tag.
  97.     global IgnoreMap
  98.     array set IgnoreMap {
  99.     x-insert {pseudo-tag used to track the insert cursor}
  100.     
  101.     {}        {Null tag can arise during cut/paste}
  102.     {/}        {End-null tag}
  103.     
  104.     hmstart    {All the head-related tags are saved elsewhere.  See head.tcl}
  105.     html    {}
  106.     /html    {}
  107.     head    {}
  108.     /head    {}
  109.     body    {}
  110.     /body    {}
  111.     title    {}
  112.     /title    {}
  113.     meta    {}
  114.     !doctype    {}
  115.     link    {}
  116.     option    {this are hidden behind a listbox and output specially}
  117.     }
  118.     
  119.     # Style-type HTML tags result in text-tags that label a range of text.
  120.     # The value of the map appears in the Style menu.
  121.     global StyleMap StyleList
  122.     array set StyleMap {
  123.     b        Bold
  124.     i        Italic
  125.     u        UnderLine
  126.     address    Address
  127.     big    Big
  128.     cite    Citation
  129.     code    Code
  130.     dfn        Definition
  131.     em        Emphasis
  132.     kbd        Keyboard
  133.     samp        Sample
  134.     strong        Strong
  135.     small        Small
  136.     tt        Teletype
  137.     var        Variable
  138.     center        Center
  139.     strike        StrikeThrough
  140.     sup        Superscript
  141.     sub        Subscript
  142.     a        {not in a menu - only for PlainText and RemoveStyle}
  143.     font        {not in a menu - only for PlainText and RemoveStyle}
  144.     }
  145.     # These sort at the same level as text styles,
  146.     # but should not be affected by RemoveStyle
  147.     array set FormItemMap {
  148.     textarea {for output sorting}
  149.     select {for output sorting}
  150.     }
  151.     # Order for the Style menu
  152.     set StyleList {
  153.     b i u address cite code dfn em kbd samp strong tt var center big small strike sub sup
  154.     }
  155.     
  156.     # The ParaMap defines the Paragraph menu.
  157.     # Note - this is hacked in window.tcl to include other stuff, too
  158.     global ParaMap ParaList
  159.     array set ParaMap {
  160.     p        Basic
  161.     div        {not in menu this way - see window.tcl}
  162.     h1        "Heading 1"
  163.     h2        "Heading 2"
  164.     h3        "Heading 3"
  165.     h4        "Heading 4"
  166.     h5        "Heading 5"
  167.     h6        "Heading 6"
  168.     blockquote    BlockQuote
  169.     pre        Preformatted
  170.     }
  171.     set ParaList {
  172.     p h1 h2 h3 h4 h5 h6 blockquote pre
  173.     }
  174.     
  175.     # The ListMap and ListList define the List menu
  176.     global ListMap ListList
  177.     array set ListMap {
  178.     ul        Unordered
  179.     ol        Ordered
  180.     dl        Definition
  181.     menu    Menu
  182.     dir        Directory
  183.     }
  184.     set ListList {
  185.     ul ol dl menu dir
  186.     }
  187.     
  188.     # The UnPMap is used to turn of <p> tags that are unclosed
  189.  
  190.     global UnPMap
  191.     array set UnPMap [array get NodeMap]
  192.     array set UnPMap [array get ListMap]
  193.     array set UnPMap [array get ListSingletonMap]
  194.     array set UnPMap [array get StructureMap]
  195.     array set UnPMap {
  196.     /hmstart    {This is a trick to get unclosed nodes handled}
  197.     }
  198.  
  199.     # TableMap is defined in the experimental table.tcl (optionally)
  200.     global TableMap
  201.  
  202.     # The AllMap records state about every known tag
  203.     global KnownMap
  204.     foreach map {NodeMap StructureMap SingletonMap ListSingletonMap
  205.         HighSingletonMap BreakMap IgnoreMap StyleMap FormItemMap
  206.         ParaMap ListMap TableMap} {
  207.     array set KnownMap [array get $map]
  208.     }
  209.  
  210.     # SortMap is used to sort HTML tags that occur at the same location.
  211.     # It determines the way tags nest in output.
  212.     # param < /strong < /h2 < /ol < /form < form < ol < li < h2 < strong < img
  213.     # See OutputSortHtags
  214.  
  215.     global SortMap
  216.  
  217.     set order 1
  218.     foreach name [array names HighSingletonMap] {
  219.     set SortMap($name) $order
  220.     }
  221.     incr order
  222.     foreach style [array names StyleMap] {
  223.     set SortMap(/$style) $order
  224.     }
  225.     # Same rank as Style
  226.     foreach formitem [array names FormItemMap] {
  227.     set SortMap(/$formitem) $order
  228.     }
  229.     incr order
  230.     foreach node [array names NodeMap] {
  231.     set SortMap(/$node) $order
  232.     }
  233.     incr order
  234.     foreach list [array names ListMap] {
  235.     set SortMap(/$list) $order
  236.     }
  237.     global SortListEnd
  238.     set SortListEnd $order
  239.     
  240.     incr order
  241.     foreach name [array names TableMap] {
  242.     set SortMap(/$name) $order
  243.     }
  244.     incr order
  245.     foreach name [array names StructureMap] {
  246.     set SortMap(/$name) $order
  247.     }
  248.     incr order
  249.     foreach name [array names StructureMap] {
  250.     set SortMap($name) $order
  251.     }
  252.     incr order
  253.     foreach name [array names TableMap] {
  254.     set SortMap($name) $order
  255.     }
  256.     
  257.     incr order
  258.     foreach list [array names ListMap] {
  259.     set SortMap($list) $order
  260.     }
  261.     global SortList
  262.     set SortList $order
  263.     incr order
  264.     foreach name [array names ListSingletonMap] {
  265.     set SortMap($name) $order
  266.     }
  267.     incr order
  268.     foreach node [array names NodeMap] {
  269.     set SortMap($node) $order
  270.     }
  271.     incr order
  272.     foreach style [array names StyleMap] {
  273.     set SortMap($style) $order
  274.     }
  275.     # Same rank as Style
  276.     foreach formitem [array names FormItemMap] {
  277.     set SortMap($formitem) $order
  278.     }
  279.     incr order
  280.     foreach name [array names SingletonMap] {
  281.     if {![info exists HighSingletonMap($name)] \
  282.         && ![info exists ListSingletonMap($name)]} {
  283.         set SortMap($name) $order
  284.     }
  285.     }
  286.     global SortUnknown
  287.     set SortUnknown [incr order]
  288. }
  289.